/**
 * Created by lenovo on 2017/10/30.
 */
$.fn.extend({
    dialog:function (params) {
        if(typeof(params)=='object'){
            var obj = {title:'默认标题',btnValue:'确认',btnBind:null,btnBinds:null,type:'create'};
            for(var prop in obj){
                obj[prop] = params[prop] || obj[prop];
            }
            if(obj.type=='create'){
                var html = '<div class="modal fade" data-backdrop="static">\
            <div class="modal-dialog">\
                <div class="modal-content">\
                <div class="modal-header">\
                <button class="close" data-dismiss="modal">&times;</button>\
            <h4 class="modal-title text-center"></h4>\
                </div>\
                <div class="modal-body"></div>\
                <div class="modal-footer">\
                <input type="button" class="text-center btn btn-primary" value="确定">\
                <input type="button" class="text-center btn btn-danger" data-dismiss="modal" value="取消">\
                </div>\
                </div>\
                </div>\
                </div>';
                var $modal = $(html);
                $modal.find(".modal-title").html(obj.title);
                this.children().appendTo($modal.find(".modal-body"));
                $modal.find("[type='button']").eq(0).val(obj.btnValue);
                $modal.find("[type='button']").eq(0).off("click").on("click",obj.btnBind);
                $modal.find("[type='button']").eq(1).off("click").on("click",obj.btnBinds);
                $modal.appendTo(this);
            }else if(obj.type=='update'){
                this.find(".modal-title").html(obj.title);
                this.find("[type='button']").eq(0).val(obj.btnValue);
                this.find("[type='button']").eq(0).off("click").on("click",obj.btnBind);
            }
        }else if(params=='open'){
            this.find(".modal").modal("show");
        }else if(params=='close'){
            this.find(".modal").modal("hide");
        }
    }
})